package lab.first;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ElCollectionServlet", value = "/elc")
public class ELCollectionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doGet(req, resp);
        //Array                                           //My firstname
        String [] firstName = {"Bill", "Scott", "Larry", "Yang"};
        //ArrayList
        List<String> lastName=new ArrayList<>();
        lastName.add("Ellison");
        lastName.add("Gates");
        lastName.add("McNealy");
        //My lastName
        lastName.add("Jile");
        //Map
        Map<String, String> company = new HashMap<String, String>();
        company.put("Ellison","Sun");
        company.put("Gates","IBM");
        company.put("McNealy","Microsoft");
        //My company
        company.put("Jile","Student");

        // set as request attribute
        req.setAttribute("fName",firstName);
        req.setAttribute("lName",lastName);
        req.setAttribute("company",company);
        //forward
        req.getRequestDispatcher("elcollection.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
